package com.scsj.supermarket.customview;

import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;

/**
 * 竖向滑动-间距
 */
public class DecorationSpacesVertical extends RecyclerView.ItemDecoration {

    private int top;
    private int bottom;
    private int left;
    private int right;

    public DecorationSpacesVertical(int space) {
        this.top=space;
        this.bottom=space;
        this.left=space;
        this.right=space;
    }

    public DecorationSpacesVertical(int topAndBottom,int leftAndRight) {
        this.top=topAndBottom;
        this.bottom=topAndBottom;
        this.left=leftAndRight;
        this.right=leftAndRight;
    }

    public DecorationSpacesVertical(int top,int bottom,int left,int right) {
        this.top=top;
        this.bottom=bottom;
        this.left=left;
        this.right=right;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {

        outRect.right = right;
        outRect.left = left;
        // Add margin only for the first item to avoid double space between items
        if (parent.getChildLayoutPosition(view) == 0) {
            outRect.top = top;
        } else {
            outRect.bottom=bottom;
            outRect.top = top;
        }
    }
}